home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 20
/
macformat_20.iso
/
mac
/
Shareware
/
Comunicaciones
/
PPP_PrefSaver 1.2
/
C Source
/
PPP-Prefs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-09
|
5KB
|
197 lines
/********************************************************************************************
* PPP-Prefs.c *
* *
* These routines were designed to handle the preferences for MacPPP. *
* [Originally Assembled] by Tony Andreoli, 12/5/95 *
* [Modified by Eric Long 4/96 to use as an IEnd with Installer Maker] *
* *
* You may use these routines freely, I only ask that you credit me somewhere in your *
* code. *
* *
* Notes: *
* • HandleError is just a simple error handler. *
* • OpenPPP_Prefs simply opens the PPP Preferences file, and returns the fRef. *
* • MacPPP considers the PREF the first part of the data fork, which consists of *
* settings that do not change across sets. It considers a CONFIG those settings *
* specific to a set. *
* • The config index starts at 0, yet thePref.max_config starts at 1. Thus if *
* thePref.max_config=4, the last config is 3 (0..3). *
* • Be sure to look in the PPP-Prefs.h file for the structure of the prefs and *
* config. *
* • Each routine opens then closes the PPP Preferences file. It is NOT left open *
* upon return. *
* *
* Purpose: *
* GetPPP_Pref - Gets the PPP preferences. *
* GetPPP_Config - Gets a specified config set. *
* PutPPP_Config - Writes config to a specified set. *
* *
********************************************************************************************/
#include "PPP-Prefs.h"
#define thePrefsFile "\pPPP Preferences"
/* Routines added to link with Fetch_Settings.c */
#if STANDALONE
void ToolBoxInit ( void );
#endif
Boolean GetUserPrefs( struct ppp_config *theConfig, OSErr *err );
/* main() and other routines have been modified in various ways to suit
the purposes of this project */
/************************ main ***************************************/
#if STANDALONE
void main( void )
#else
pascal short main(short abort,short vol,long dir,uchar *name,
unsigned short packages)
#endif
{
struct ppp_pref thePref;
struct ppp_config theConfig;
OSErr err = 0;
#if STANDALONE
ToolBoxInit();
#else
if (abort) { goto out;}
#endif
err = GetPPP_Pref(&thePref);
// If err == file not found, the PPP Prefs file isn't installed so we'll do nothing.
if (! err)
err = GetPPP_Config(&theConfig,thePref.active_config);
if (!err){
if (GetUserPrefs(&theConfig, &err))
PutPPP_Config(theConfig, thePref.active_config);
else{
if (err)
HandleError(err);
}
}
#if (! STANDALONE)
out:
return (abort);
#endif
}
/************************* ToolBoxInit ******************************/
#if STANDALONE
void ToolBoxInit ( void )
{
InitGraf ( &thePort );
InitFonts ();
InitWindows ();
InitMenus ();
TEInit ();
InitDialogs ( 0L );
InitCursor ();
}
#endif
/************************ HandleError *******************************/
void HandleError(OSErr errNum)
{
Str255 theErr;
if (errNum!=noErr) {
NumToString(errNum,theErr);
ParamText(theErr,"\p","\p","\p");
Alert(rErrorAlert,nil);
}
}
/**************************** OpenPPP_Prefs *****************************/
short OpenPPP_Prefs(OSErr *err)
{
short foundvRefNum;
long foundDirID;
short SystemFolderID;
short theResFile;
FInfo thefInfo;
*err=FindFolder(kOnSystemDisk,kPreferencesFolderType,kDontCreateFolder,&foundvRefNum,&foundDirID); /* Get location of the preferences folder */
*err = HOpen(foundvRefNum,foundDirID,thePrefsFile,fsRdWrShPerm,&theResFile);
if ((*err != noErr) && (*err != fnfErr)) { // If we can't find it, no alert, just get out.
HandleError(*err);
}
return theResFile;
}
/************************* GetPPP_Pref ********************************/
OSErr GetPPP_Pref(struct ppp_pref *thePref)
{
long count;
OSErr rc = noErr;
short prefref;
Str255 theStr;
prefref=OpenPPP_Prefs(&rc);
if (! rc){
rc = SetFPos(prefref,fsFromStart,0);
count = sizeof ( struct ppp_pref );
if ( rc == noErr) {
rc = FSRead(prefref, &count, thePref);
}
else
HandleError(rc);
FSClose(prefref);
}
return(rc);
}
/************************** GetPPP_Config **********************************/
OSErr GetPPP_Config(struct ppp_config *theConfig,short confignum)
{
long count;
OSErr rc;
short prefref;
prefref=OpenPPP_Prefs(&rc);
rc = SetFPos(prefref,fsFromStart,sizeof (struct ppp_pref)+(sizeof (struct ppp_config) * confignum));
count = sizeof ( struct ppp_config );
if ( rc == noErr) {
rc = FSRead(prefref, &count, theConfig);
}
else
HandleError(rc);
FSClose(prefref);
return(rc);
}
/*********************** PutPPP_Config ********************************/
void PutPPP_Config(struct ppp_config theConfig,short confignum)
{
long count;
OSErr rc;
short prefref;
prefref=OpenPPP_Prefs(&rc);
rc = SetFPos(prefref,fsFromStart,sizeof (struct ppp_pref)+(sizeof (struct ppp_config) * confignum));
count = sizeof ( struct ppp_config );
if ( rc == noErr) {
rc = FSWrite(prefref, &count, &theConfig);
}
else
HandleError(rc);
FSClose(prefref);
}